package com.dfz.aliyun.design.pattern.c3.adapter;

/**
 * 原player只能支持MP3格式的，为了保持原有接口不动，那么组合新的适配器进来
 */
public class AudioPlayer implements MediaPlayer{

    /** 没提适配器*/
    private MediaAdapter mediaAdapter;

    @Override
    public void play(String audioType, String fileName) {
        if ("mp3".equalsIgnoreCase(audioType)) {
            // 原接口只支持mp3，修改接口实现
            System.out.println("Playing mp3 file. Name: " + fileName);
        }

        // 新增的格式使用适配器来实现
        if ("vlc".equalsIgnoreCase(audioType) ||
        "mp4".equalsIgnoreCase(audioType)) {
            mediaAdapter = new MediaAdapter(audioType);
            mediaAdapter.play(audioType, fileName);
        }
    }
}
